import { fromJS } from 'immutable';
import * as constants from './constants';

// current: 分页当前页码
// isLoading: pagination
// orderData: 订单数据
// dialogVisible: 对话框是否显示 boolean
// dialogData: 动态
// searchId: 搜索框搜索交易编号
// searchFormValue: 搜索框需要的表格数据
const defaultState = fromJS({
  current: 1,
  isLoading: false,
  orderData: [],
  dialogVisible: false,
  dialogData: [],
  searchId: '',
  searchFormValue: {
    id: '',
  }
});

export default (state = defaultState, action) => {
  switch(action.type) {
    case constants.GET_ORDERDATA:
      return state.set("orderData", fromJS(action.orderData));
    case constants.OPEN_DIALOG:
      return state.merge({
        dialogVisible: true,
        dialogData: fromJS(action.dialogData)
      });
    case constants.CLOSE_DIALOG:
      return state.set("dialogVisible", false);
    case constants.SEARCHFORM_CHANGE:
      return state.set("searchId", action.searchId);
    default:
      return state;
  }
}